import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UserService } from '../user/user.service';
import { ConfigService } from '@nestjs/config';
import { PassportModule } from '@nestjs/passport';
import { StrategyEnum } from '@/common/enums/strategy.enum';
import { JwtModule } from '@nestjs/jwt';
import { EnvEnum } from '@/common/enums/env.enum';
import { LocalStrategy } from './strategies/local.strategy';
import { JwtAccessStrategy } from './strategies/jwt-access.strategy';
import { JwtRefreshStrategy } from './strategies/jwt-refresh.strategy';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: StrategyEnum.JWT_ACCESS }),
    JwtModule.registerAsync({
      useFactory: async (configService: ConfigService) => ({
        publicKey: Buffer.from(configService.get<string>(EnvEnum.JWT_PUBLIC_KEY), "base64").toString("utf-8"),
        privateKey: Buffer.from(configService.get<string>(EnvEnum.JWT_PRIVATE_KEY), "base64").toString("utf-8"),
        signOptions: {
          algorithm: 'RS256',
        }
      }),
      inject: [ConfigService]
    })
  ],
  controllers: [AuthController],
  providers: [AuthService, UserService, ConfigService, LocalStrategy, JwtAccessStrategy, JwtRefreshStrategy],
})
export class AuthModule { }
